home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
ulib
/
vstrcat.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
2KB
|
76 lines
/***********************************************************************
* $Id: vstrcat.c,v 0.80 1994/02/24 09:48:11 zhao Exp $
*
*. Copyright(c) 1993,1994 by T.C. Zhao
* All rights reserved.
*.
* Similar to strcat, but takes variable number of argument
*
***********************************************************************/
#if !defined(lint) && defined(F_ID)
char *id_vstrcat = "$Id: vstrcat.c,v 0.80 1994/02/24 09:48:11 zhao Exp $";
#endif
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <malloc.h>
#include "ulib.h"
/* VARARGS1 */
char *
vstrcat(const char *s1,...)
{
register size_t total = 0;
register char *ret, *p;
va_list ap;
if (!s1)
return 0;
total = strlen(s1);
/* record total length */
va_start(ap, s1);
while ((p = va_arg(ap, char *)) != (char *) 0)
total += strlen(p);
va_end(ap);
if (!(ret = malloc(total + 1)))
return 0;
strcpy(ret, s1);
va_start(ap, s1);
while ((p = va_arg(ap, char *)) != (char *) 0)
strcat(ret, p);
va_end(ap);
return ret;
}
/****** so to protect from M_DBG *******/
void
free_vstrcat(void *p)
{
free(p);
}
#ifdef TEST
#include <stdio.h>
#include <string.h>
#include "protolib.h"
main()
{
char *p = vstrcat("Hello", " World", "!", (char *) 0);
char *q = vstrcat(p, " again", " and again", (char *) 0);
char *l = vstrcat(q, " again", " and again", (char *) 0);
fprintf(stderr, "%s\n", p);
fprintf(stderr, "%s\n", q);
fprintf(stderr, "%s\n", l);
free(p);
free(q);
free(l);
}
#endif